﻿using System;
using System.Collections;
using System.Collections.Generic;
using Zor_DAL;
using Zor_Modes;

namespace Zor_Bll
{
    /// <summary>
    /// 部门管理
    /// </summary>
    public class Sys_Department_Bll<T> where T : class
    {

        /// <summary>
        /// 获取部门管理列表
        /// </summary>
        /// <returns></returns>
        public static List<T> GetDepartmentList()
        {
            return Sys_Department_DAL<T>.GeDepartmentList();
        }

        /// <summary>
        /// 获取部门不为4的数据
        /// </summary>
        /// <param name="flag">是否查找仅为4类别的部门 </param>
        /// <returns></returns>
        public static List<T> SelectDtparentid()
        {
            return Sys_Department_DAL<T>.SelectDtparentid();
        }

        /// <summary>
        /// 新增部门
        /// </summary>
        /// <param name="department">部门</param>
        /// <returns></returns>
        public static BaseAnswer InsertDepartment(Sys_Department department)
        {
            BaseAnswer bar = Sys_Department_DAL<T>.InsertDepartment(department);
            if(bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "增加成功！" : "新增失败,请检查部门名称是否重复！";
            return bar;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="department"></param>
        /// <returns></returns>
        public static BaseAnswer AlterDepartment(Sys_Department department, string oldName)
        {
            BaseAnswer bar = Sys_Department_DAL<T>.AlterDepartment(department, oldName);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "修改成功！" : "修改失败,请检查部门名称是否重复！";
            return bar;
        }

        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="id">删除的Id</param>
        /// <returns></returns>
        public static BaseAnswer DeleteDepartment(string id)
        {
            BaseAnswer bar = Sys_Department_DAL<T>.DeleteDepartment(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "删除成功！" : "删除失败，请重试！";
            return bar;
        }

        /// <summary>
        /// 查询要删除的部门是否拥有下级部门
        /// </summary>
        /// <param name="id">查询删除的Id</param>
        /// <returns></returns>
        public static BaseAnswer SelectDepartment(string id)
        {
            List<T> rsDepartmentList = Sys_Department_DAL<T>.SelectDepartment(id);
            BaseAnswer bar = new BaseAnswer();
            if (rsDepartmentList.Count > 0)
            {
                bar.AnswerMeg = "当前部门拥有下级部门，不允许删除！";
            }
            else
            {
                bar.AnswerType = BaseAnswer.Answers.Succee;
            }
            return bar;
        }

    }
}
